/** GW Common.  This file holds various common routines to support GeoWiki.
*/

/** Namespace for geo wiki things.  This namespace is used to hold all the GW
    Javascript names to keep them distinct from other names.
*/
var GW = YAHOO.namespace("GeoWiki");

/** Make tool tip helper.  Tooltips created by this helper are held in 
    GW.MakeTT._ids_ indexed by the element id of the element to which the
    tool tip is attached.
    
    @method MakeTT
    @param (string) id The element id to attach the tool tip to
    @param (string) text The tool tip text
    @return (YAHOO.widget.Tooltip)
*/
GW.MakeTT = function( id, text ){
    if( !GW.MakeTT._ids_ ){ 
        GW.MakeTT._ids_ = {};
    };
    var tmp = new YAHOO.widget.Tooltip( id + '_tt_', 
        { context: id, text: text }
    );
    GW.MakeTT._ids_[id] = tmp;
    return tmp;
};

/** Logger methods 
*/
/** LogInit initializes the log reader and hides it.
    @method LogInit
    @param none
    @return none
*/
GW.LogInit = function(){
    GW._logReader = new YAHOO.widget.LogReader(null, 
        {width: '450px', verboseOutput: false});
    GW._logReader.hide();       // initially hidden<script type="text/javascript" >
    GW.LogShow._show = false;   // traks show/hide state of log
};
/** LogShow toggle.  Shows log if it is hidden.  Hides it if it is visible.
    @method LogShow
    @param none
    @return none
*/
GW.LogShow = function(){ 
    if( GW.LogShow._show ){
        GW._logReader.hide();
        GW.LogShow._show = false;
    } else {
        GW._logReader.show();
        GW.LogShow._show = true;
    };
};
/** YAHOO.log helper.  This wraps YAHOO.log as a place holder for additional
    logging support.
    
    @method Log
    @param (string) The log message
    @param (string) Message severity/category.  info, warn, error, dbg, etc.
    @param (string) Issuig component.
    @return none
*/
GW.Log = function( message, severity, component){
    YAHOO.log( message, severity, component);
};


/** Onload/OnUnload support */
/** Base onload function.  Initializes various common page elements.  Pages that
    require page specific onload support should define GW.PageOnload.
    
    @method GW.Onload
    @param none
    @return none
*/
GW.OnLoad = function(){
    // setup our logreader
    GW.LogInit();
    // attach our event listeners
    YAHOO.util.Event.addListener("idLogShowBTN", "click", GW.LogShow, {}, false);
    // invoke page specific onload function
    if( GW.PageOnload ) {
        GW.PageOnload();
    };
};
/** Base onunload function.  Do any base required cleanup.  Pages that
    require page specific onunload support should define GW.PageOnUnload.
    
    @method GW.OnUnload
    @param none
    @return none
*/
GW.OnUnload = function(){
    if( GW.PageOnUnLoad ) {
        GW.PageOnUnload();
    }
};
        
/** Temp functions, todo: put where they really belong */
function EditPage( pageName ) {
    if( !pageName ) {
        var pageName = window.prompt("Enter the WikiName of your new page:");
    };
    if (pageName) {
        location.href = '/wikiedit/' + pageName;
    };
};
